﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace FastCodeGeneration.Core.Framework
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T">domian类</typeparam>
    public interface IBaseServices<T> where T : class, new()
    {

        /// <summary>
        /// 根据主值查询单条数据
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>泛型实体</returns>
        T SelectById(dynamic id);


        /// <summary>
        /// 根据id集合查询
        /// </summary>
        /// <param name="ids">主键值</param>
        /// <returns>泛型实体</returns>
        List<T> SelectByIds(IEnumerable<dynamic> ids);

        /// <summary>
        /// 查询全部数据
        /// </summary>
        /// <returns></returns>
        List<T> SelectAll();


        /// <summary>
        /// 查询count
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <returns></returns>
        long SelectCount(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <returns></returns>
        T SelectOne(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 查询集合
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <returns></returns>
        List<T> SelectList(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page">分页封装</param>
        /// <param name="queryWrapper">查询条件</param>
        /// <returns></returns>
        IPage<T> SelectPage(IPage<T> page, QueryWrapper<T> queryWrapper);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="">前端条件封装</param>
        /// <returns></returns>
        IPage<T> SelectPage(Condition condition);

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">对象</param>
        /// <returns></returns>
        T InsertEntity(T entity);

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="entities">对象集合</param>
        /// <returns>行数</returns>
        bool BatchInsert(List<T> entities);


        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">对象</param>
        /// <returns></returns>
        bool UpdateEntity(T entity);

        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="entities">对象集合</param>
        /// <returns>行数</returns>
        bool BatchUpdate(List<T> entities);


        /// <summary>
        /// 添加或更新
        /// </summary>
        /// <param name="entity">对象</param>
        /// <returns>行数</returns>
        bool Save(T entity);


        /// <summary>
        /// 添加或更新
        /// </summary>
        /// <param name="entities">对象集合</param>
        /// <returns>行数</returns>
        bool BatchSave(List<T> entities);


        /// <summary>
        /// 根据id删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        bool DeleteById(dynamic id);

        /// <summary>
        /// 根据id集合
        /// </summary>
        /// <param name="id">主键集合</param>
        /// <returns></returns>
        bool DeleteByIds(IEnumerable<dynamic> ids);

        /// <summary>
        /// 根据对象删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool DeleteByEntity(T entity);


        /// <summary>
        /// 根据对象集合删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool DeleteByEntities(List<T> entities);

    }
}
